home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Macintosh Debugging / DoubleTrouble / DoubleTrouble Read Me next >
Encoding:
Text File  |  1992-10-25  |  1.9 KB  |  36 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    DoubleTrouble - by Greg Marriott
  3. ;
  4. ;    © 1992, Apple Computer, Inc.
  5. ;
  6. ;    DoubleTrouble is a debugging utility made to catch a common programming error:
  7. ;    freeing a handle that has already been freed.  (I call these errors “double
  8. ;    dispose bugs”…)
  9. ;
  10. ;    When _DisposeHandle is called on a handle, the memory manager adds the handle
  11. ;    to its “free list,” a linked list of handles available for the allocator to use.
  12. ;    Calling _DisposeHandle on that handle again is usually benign.  The memory
  13. ;    manager dereferences the handle, pointing to the next handle in the free list.
  14. ;    If the the dereferenced handle points to the first handle in a master pointer block,
  15. ;    however, the handle appears valid because it points to a real block.  The memory
  16. ;    manager fails to realize the block is NOT a relocatable block (all master pointer
  17. ;    blocks are nonrelocatable), and marks it free (yikes!).  The freed master pointer
  18. ;    block is then used in a future allocation (usually very soon after being freed).
  19. ;    This mangles several master pointers and the free list.  Crashes soon follow.
  20. ;
  21. ;    This kind of bug is very hard to track down, and usually difficult to reproduce,
  22. ;    because master pointer blocks contain 64 handles (by default, some programs
  23. ;    change this behavior).  So, this situation only comes up about 1/64th of the
  24. ;    time.  When it happens, though, the results are inevitably catastrophic.
  25. ;
  26. ;    DoubleTrouble compares each handle being disposed to every handle in the free list of
  27. ;    the zone containing the handle.  If the handle is already in the free list,
  28. ;    DoubleTrouble breaks into the debugger with a message indicating what’s going on.
  29. ;    Continuing execution will stuff memWZErr (WhichZone failed, -111) into MemErr
  30. ;    and d0 and return to the caller (and NOT call through to _DisposeHandle).
  31. ;    
  32. ;    Greg Marriott
  33. ;    Just Some Guy
  34. ;    Apple Computer, Inc.
  35. ;    20525 Mariani Ave. MS/81-GC
  36. ;    Cupertino, CA    95014